#include <iostream>
#include <bits/stdc++.h>

using namespace std;

class Solution {
public:
    //动态规划
    vector<string> restoreIpAddresses(string s) {
        string cur = "";
        dfs(0, s, cur, 0);
        return res;
    }

    vector<string> res;

    void dfs(int index, string &s, string cur, int count) {
        int n = s.size();
        if (index >= n) {
            if (count == 4) res.push_back(cur.substr(0, cur.size() - 1));
            return;
        }
        if (count >= 4) {
            return;
        }
        int sum = 0;
        for (int i = index; i < index + 3 && i < n; i++) {
            sum = 10 * sum + s[i] - '0';
            if (sum > 255 || sum < 0) {
                break;
            }
            string temp = string(cur);
            temp.append(to_string(sum) + ".");
            dfs(i + 1, s, temp, count + 1);
            if (sum == 0) {
                break;
            }
        }
    }

    int calculate(string s) {
        
    }
};


int main() {

    Solution solution;
    auto res = solution.restoreIpAddresses("101023");
    for (const auto &item: res) {
        cout << item << "\n";
    }
    cout << "\n";
    return 0;
}